package com.ma.service;

import com.ma.client.ProductClient;
import io.github.resilience4j.bulkhead.annotation.Bulkhead;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.retry.annotation.Retry;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

@Service
public class OrderService {

    private final ProductClient productClient;

    public OrderService(ProductClient productClient) {
        this.productClient = productClient;
    }

    public Map<String, Object> createOrder(Integer productId) {
        Map<String, Object> prod = productClient.detail(productId);
        return Map.of(
                "orderId", UUID.randomUUID().toString(),
                "product", prod,
                "status", "CREATED"
        );
    }

    public Map<String, String> getHeaders(Map<String, String> fakeHeaders) {
        return productClient.getHeaders(fakeHeaders);
    }

    public String hello(){
        return productClient.hello();
    }

    public Map<String, Object> fallbackCreate(Integer productId, Throwable ex) {
        return Map.of(
                "orderId", UUID.randomUUID().toString(),
                "product", Map.of("id", productId),
                "status", "DEGRADED",
                "reason", ex.getClass().getSimpleName()
        );
    }

}

